package com.hdd.art.biz.member.controller;


import com.hdd.art.biz.login.dto.WXRegisterRequest;
import com.hdd.art.biz.member.dto.MemberDo;
import com.hdd.art.biz.member.dto.MemberInfoDo;
import com.hdd.art.biz.member.dto.MemberVo;
import com.hdd.art.biz.member.dto.VerifyListDo;
import com.hdd.art.biz.member.entity.Member;
import com.hdd.art.biz.member.service.MemberService;
import com.hdd.art.biz.painting.entity.PaintingWorks;
import com.hdd.art.biz.painting.service.PaintingWorksService;
import com.hdd.art.biz.show.entity.ArtShow;
import com.hdd.art.biz.show.service.ArtShowService;
import com.hdd.art.dto.AppResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * <p>
 * 系统用户表 前端控制器
 * </p>
 *
 * @author fang
 * @since 2021-06-27
 */
@RestController
@RequestMapping("/member")
@Api(value = "会员",tags = {"会员相关接口"})
public class MemberController {


    @Autowired
    private MemberService memberService;
    @Autowired
    private PaintingWorksService paintingWorksService;

    @Autowired
    private ArtShowService artShowService;

    @PostMapping("/findUserByUserId")
    @ApiOperation(value = "根据userId获取用户信息（美术馆）" ,notes = "")
    public AppResponse info(@Valid @RequestBody MemberDo memberDo ){
        AppResponse response = new AppResponse();
        Member member =  memberService.findMemberByUserId(memberDo);
        if(member!=null){
            MemberVo vo = new MemberVo();
            BeanUtils.copyProperties(member,vo);
            vo.setUserId(member.getUserId());
            vo.setProvince(member.getProvince());
            vo.setCity(member.getCity());
            vo.setArea(member.getArea());
            vo.setLike(122222);
            vo.setPraises(233333);
            vo.setShare(222222222);
            vo.setFans(12222);
            vo.setUserId(member.getUserId());
            vo.setType(1);
            ArtShow artShow = artShowService.findArtShowByUserId(vo.getUserId());
            if(artShow!=null){
                vo.setArtId(artShow.getArtId());
            }
            vo.setPhone("100000222");
            response.setItem(vo);
        }
        return response;
    }


    @PostMapping("/ordinaryUser")
    @ApiOperation(value = "根据userId获取用户信息（普通用户 测试userId-300）" ,notes = "")
    public AppResponse ordinaryUser(@Valid @RequestBody MemberDo memberDo ){
        AppResponse response = new AppResponse();
        Member member =  memberService.findMemberByUserId(memberDo);
        if(member!=null){
            MemberVo vo = new MemberVo();
            BeanUtils.copyProperties(member,vo);
            vo.setProvince(member.getProvince());
            vo.setCity(member.getCity());
            vo.setArea(member.getArea());
            vo.setLike(100);
            vo.setShare(2550);
            vo.setType(0);
            vo.setSex(1);
            response.setItem(vo);
        }
        return response;
    }


    @PostMapping("/update")
    @ApiOperation(value = "修改我的信息" ,notes = "")
    public AppResponse update(@Valid @RequestBody MemberInfoDo  memberInfoDo ){
        AppResponse response = new AppResponse();
        Member member = new Member();
        BeanUtils.copyProperties(memberInfoDo,member);
        memberService.udpateMember(member);
        return response;
    }

    @PostMapping("/updateHead")
    @ApiOperation(value = "修改我的头像" ,notes = "")
    public AppResponse updateHead(@Valid @RequestBody MemberInfoDo memberInfoDo ){
        AppResponse response = new AppResponse();
        Member member = new Member();
        BeanUtils.copyProperties(memberInfoDo,member);
        memberService.udpateMember(member);
        return response;
    }



    @PostMapping("/myWorks")
    @ApiOperation(value = "我的作品" ,notes = "")
    public AppResponse myWorks(@Valid @RequestBody VerifyListDo verifyListDo ){
        AppResponse response = new AppResponse();
        response.setItems(paintingWorksService.getMyWorkList(verifyListDo.getUserId(),verifyListDo.getPageNo(),verifyListDo.getPageSize()));
        response.setTotals(10L);
        return response;
    }




    @PostMapping("/myWorksDetails")
    @ApiOperation(value = "我的作品详情列表" ,notes = "")
    public AppResponse myWorksDetails(@Valid @RequestBody VerifyListDo verifyListDo ){
        AppResponse response = new AppResponse();
        response.setItems(paintingWorksService.myWorksDetails("",verifyListDo.getUserId(),verifyListDo.getPageNo(),verifyListDo.getPageSize()));
        response.setTotals(10L);
        return response;
    }



    @PostMapping("/myContribute")
    @ApiOperation(value = "我的投稿" ,notes = "")
    public AppResponse myContributes(@Valid @RequestBody VerifyListDo verifyListDo ){
        AppResponse response = new AppResponse();
        response.setItems(paintingWorksService.getMyVerifyList(verifyListDo.getUserId(),verifyListDo.getPageNo(),verifyListDo.getPageSize()));
        response.setTotals(1L);
        return response;
    }



}

